<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="zh-CN">
<head>
<link rel="stylesheet" href="<%=path%>/css/manager/banner2.css">
<script type="text/javascript"
	src="<%=path%>/js/manager/jquery-1.8.2.js"></script>

<title>编辑banner</title>
</head>
 
<body>
		<!--
        	作者：offline
        	时间：2016-12-22d
        	描述：论坛学人管理内容头部
        -->
		<div class="bbs_mist_div1">Banner管理</div>
		<div class="banner2_div2">
		<form action="banmanage.htm" id="sform" method="post">
		<input type="hidden"
				id="pageIndex" name="pageInfo.pageIndex" value="${banner.pageInfo.pageIndex}" />
			<input type="hidden" id="pageSize" name="pageInfo.pageSize"
				value="${banner.pageInfo.pageSize}" />
			<input type="hidden" id="markManage" name="markManage"
				value="${banner.markManage}" />
			<input type="hidden" id="condition" name="condition"
				value="${banner.condition}" />
			<input type="hidden" id="banId" name="banId"
				value="${banner.banId}" />
				<input type="hidden" id="sysuserId" name="banAdduser" value="${back_user.sysuserId}"/>
			<div class="news2_div2_div1">
        		<span class="news2_div2_div1_sp1"><c:if test="${banner.markManage==1}">添加</c:if><c:if test="${banner.markManage==2}">修改</c:if>Banner</span>
        	</div>
        	<div class="banner2_div2_div1">
        		<div class="banner2_div2_div1_div1">banner名称</div>
        		<input class="banner2_div2_div1_in1" type="text" placeholder="输入banner名称" name="banName" id="banName" value="${banner.banName}"/>
        		<div class="banner2_div2_div1_div2">还剩<span>30</span>字</div>
        	</div>
        	<div class="banner2_div2_div2">
        		<div class="banner2_div2_div1_div1">排序</div>
        		<c:if test="${banner.markManage==2 && banner.banStatus==2}">0（不展示状态下的banner不参与排序）
        		<input type="hidden" id="banOrder" name="banOrder" value="100"/>
        		</c:if>
        		<c:if test="${banner.banStatus!=2}">
        		<select class="banner2_div2_div2_se1" id="banOrder_sel" onchange="setSel()">
        			<option <c:if test="${banner.banOrder==1}">selected="selected"</c:if>>1</option>
        			<option <c:if test="${banner.banOrder==2}">selected="selected"</c:if>>2</option>
        			<option <c:if test="${banner.banOrder==3}">selected="selected"</c:if>>3</option>
        			<option <c:if test="${banner.banOrder==4}">selected="selected"</c:if>>4</option>
        			<option <c:if test="${banner.banOrder==5}">selected="selected"</c:if>>5</option>
        			<option <c:if test="${banner.banOrder==6}">selected="selected"</c:if>>6</option>
        			<option <c:if test="${banner.banOrder==7}">selected="selected"</c:if>>7</option>
        			<option <c:if test="${banner.banOrder==8}">selected="selected"</c:if>>8</option>
        			<option <c:if test="${banner.banOrder==9}">selected="selected"</c:if>>9</option>
        		</select>
        		<input type="hidden" id="banOrder" name="banOrder" value="${banner.banOrder}"/>
        		</c:if>
        	</div>
        	<div class="banner2_div2_div3">
        		<div class="banner2_div2_div1_div1">参与链接</div>
        		<input class="banner2_div2_div3_in1" type="text" id="banUrl" name="banUrl" value="${banner.banUrl}"/>
        	</div>
        	<div class="banner2_div2_div6">
        		<div class="banner2_div2_div1_div1">内容简介</div>
        		<%-- <input class="banner2_div2_div3_in1" type="text" id="banContent" name="banContent" value="${banner.banContent}"/> --%>
        		<textarea class="banner2_div2_div3_ta1" id="banContent" name="banContent">${banner.banContent}</textarea>
        	</div>
        	<div class="banner2_div2_div4">
        		<div class="banner2_div2_div1_div1">banner图片</div>
        		
        		<input class="banner2_div2_div4_in1" type="button" />
        		<input class="shangchuan_in1"  type="file" onchange="selectImagez(this);" id="" />
        		<p>1、图片尺寸为：750px*380px，仅支持jpg.jpeg.和png.格式；</p>
        		<p>2、图片要清晰，不能虚化；</p>
        		<img class="shangchuan_img" id="imagez" src="/upload/images/banner/${banner.banImg}" />
        		<input type="hidden" name="banImg" id="banImg" value="${banner.banImg}"/>
        			 <input type="hidden" name="oldImg" id="oldImg" value="${banner.banImg}"
						disabled="disabled" />
        	</div>
        	<div class="banner2_div2_div5">
        		<input class="banner2_div2_in1" type="submit" onclick="return submitCheck()" value=""/>
        		<input class="banner2_div2_in2" type="submit"  value="" onclick="back()"/>
        	</div>
        	
        	</form>
		</div>
</body>

<script type="text/javascript">
	//提交验证
	function submitCheck() {
		//验证管理员登录
		var sysuserId=$("#sysuserId").val();
		if(sysuserId.length==0){
			alert("管理员登录失效，请重新登录");
			window.open("<%=path%>/login/beforelogin.htm");
			return false;
		}
		//banner名称
		var banName = $.trim($("#banName").val());
		if (banName.length == 0) {
			alert("banner名称不能为空！");
			$("#banName").focus();
			return false;
		} else {
			$("#banName").val(banName);
		}
        //排序
        var banOrder=$("#banOrder").val();
        if(banOrder.length==0){
        	$("#banOrder").val(1);
        }
		//参与链接
		var banUrl=$("#banUrl").val();
		if (banUrl.length == 0) {
			alert("banner链接不能为空！");
			$("#banUrl").focus();
			return false;
		} else {
			$("#banUrl").val(banUrl);
		}
		//内容简介
		var banContent=$("#banContent").val();
		if (banContent.length == 0) {
			alert("banner内容简介不能为空！");
			$("#banContent").focus();
			return false;
		} else {
			$("#banContent").val(banContent);
		}
		//图片
		var banImg=$("#banImg").val();
		if (banImg.length == 0) {
			alert("请上传banner图片！");
			return false;
		} else {
			$("#banImg").val(banImg);
		}
		
	 
		return true;
	}
	//返回事件
	function back() {
		$("#sform").attr("action", "banlist.htm");
		$("#sform").submit();
	}
	//设置下拉框改变事件
	function setSel(){
		var banOrder_sel= $("#banOrder_sel").val();
		$("#banOrder").val(banOrder_sel);
	}
	
	//上传头像
	function selectImagez(file) {
		//控制显示oldImg路径
		$('#oldImg').attr("disabled",false); 
		if (!file.files || !file.files[0]) {
			return;
		}
		var image = '';
		var reader = new FileReader();
		reader.onload = function(evt) {
			document.getElementById('imagez').src = evt.target.result;
			image = evt.target.result;
			$.ajax({
				type : "post",
				url : '<%=path%>/imageController/updateImg.htm',
						data : {
							image : image,
							oldImg : file.id,
							path : "/upload/images/banner/"
						},
						async : false,
						dataType : 'json',
						success : function(data) {
							//alert(data);//返回上传图片的名字
							$("#banImg").val(data);
							$("#oldImg").val(data);
							file.id = data;
						},
						error : function(err) {
							alert('网络故障');
						}
					});
		}
		reader.readAsDataURL(file.files[0]);
		return false;
	}
</script>
</html>

